<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <!-- 用户展示功能 -->
            <template v-if="user_role === 'user'">
                <template v-for="item in user_items">
                    <template v-if="item.subs">
                        <el-submenu :index="item.index" :key="item.index">
                            <template slot="title">
                                <i :class="item.icon"></i>
                                <span slot="title">{{ item.title }}</span>
                            </template>
                            <template v-for="subItem in item.subs">
                                <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                    <template slot="title">{{ subItem.title }}</template>
                                    <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{
                                        threeItem.title
                                    }}</el-menu-item>
                                </el-submenu>
                                <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
                            </template>
                        </el-submenu>
                    </template>
                    <template v-else>
                        <el-menu-item :index="item.index" :key="item.index">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </el-menu-item>
                    </template>
                </template>
            </template>
            <!-- 快递员展示功能 -->
            <template v-if="user_role === 'staff'">
                <template v-for="item in staff_items">
                    <template v-if="item.subs">
                        <el-submenu :index="item.index" :key="item.index">
                            <template slot="title">
                                <i :class="item.icon"></i>
                                <span slot="title">{{ item.title }}</span>
                            </template>
                            <template v-for="subItem in item.subs">
                                <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                    <template slot="title">{{ subItem.title }}</template>
                                    <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{
                                        threeItem.title
                                    }}</el-menu-item>
                                </el-submenu>
                                <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
                            </template>
                        </el-submenu>
                    </template>
                    <template v-else>
                        <el-menu-item :index="item.index" :key="item.index">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </el-menu-item>
                    </template>
                </template>
            </template>
            <!-- 展示功能 -->
            <template v-if="user_role === 'admin'">
                <template v-for="item in admin_items">
                    <template v-if="item.subs">
                        <el-submenu :index="item.index" :key="item.index">
                            <template slot="title">
                                <i :class="item.icon"></i>
                                <span slot="title">{{ item.title }}</span>
                            </template>
                            <template v-for="subItem in item.subs">
                                <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                    <template slot="title">{{ subItem.title }}</template>
                                    <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{
                                        threeItem.title
                                    }}</el-menu-item>
                                </el-submenu>
                                <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
                            </template>
                        </el-submenu>
                    </template>
                    <template v-else>
                        <el-menu-item :index="item.index" :key="item.index">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </el-menu-item>
                    </template>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            user_role: '',
            collapse: false,

            //用户权限列表
            user_items: [
                {
                    icon: 'el-icon-s-home',
                    index: 'userDashBoard',
                    title: '我的首页'
                },
                {
                    icon: 'el-icon-message-solid',
                    index: 'userSystemNotice',
                    title: '我的通知'
                },
                {
                    icon: 'el-icon-s-cooperation',
                    index: 'MyPackage',
                    title: '我的包裹'
                },
                {
                    icon: 'el-icon-chat-line-round',
                    index: 'MyAppointment',
                    title: '我的预约'
                },
                {
                    icon: 'el-icon-circle-close',
                    index: 'PackageRefused',
                    title: '包裹拒签'
                },
                {
                    icon: 'el-icon-s-custom',
                    index: 'MakeAppointment',
                    title: '预约上门'
                },
                {
                    icon: 'el-icon-position',
                    index: 'SendPackage',
                    title: '寄件'
                }
            ],
            //快递员权限列表
            staff_items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'staffDashBoard',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-message-solid',
                    index: 'staffSystemNotice',
                    title: '系统通知'
                },
                {
                    icon: 'el-icon-s-custom',
                    // index: '3',
                    title: '个人中心',
                    subs: [
                        {
                            icon: 'el-icon-lx-cascades',
                            index: 'InfoModify',
                            title: '完善信息'
                        },
                        {
                            icon: 'el-icon-lx-cascades',
                            index: 'UpdatePwd',
                            title: '修改密码'
                        }
                    ]
                },
                {
                    icon: 'el-icon-truck',
                    index: 'ExpressInfo',
                    title: '快递信息'
                },
                {
                    icon: 'el-icon-discount',
                    index: 'Import',
                    title: '入库管理'
                },
                {
                    icon: 'el-icon-price-tag',
                    index: 'Export',
                    title: '出库管理'
                },
                {
                    icon: 'el-icon-phone',
                    index: 'ConfirmAppointment',
                    title: '寄件预约'
                },
                {
                    icon: 'el-icon-present',
                    index: 'PackageStranded',
                    title: '包裹滞留'
                },
                 {
                    icon: 'el-icon-present',
                    index: 'PickUpCodeManagement',
                    title: '货码管理'
                }
            ],
            //管理员权限列表
            admin_items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'adminDashBoard',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-message-solid',
                    index: 'adminSystemNotice',
                    title: '系统通知'
                },
                {
                    icon: 'el-icon-user',
                    index: 'StaffManagement',
                    title: '员工管理'
                },
                 
                {
                    icon: 'el-icon-s-custom',
                    index: 'UserManagement',
                    title: '用户管理'
                },
                {
                    icon: 'el-icon-office-building',
                    index: 'CompanyManagement',
                    title: '公司管理'
                },
            
                {
                    icon: 'el-icon-s-grid',
                    index: 'adminPickUpCodeManagement',
                    title: '货码管理'
                },
                {
                    icon: 'el-icon-s-data',
                    index: 'DailyStatistics',
                    title: '每日统计'
                },
                {
                    icon: 'el-icon-edit-outline',
                    index: 'MonthlyStatistics',
                    title: '每月总结'
                }
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        this.user_role = localStorage.getItem('role');
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', (msg) => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
